package com.kc.business.service.impl;

import com.kc.business.domain.BizScenic;
import com.kc.business.mapper.BizScenicMapper;
import com.kc.business.service.IBizScenicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.lang.reflect.Array;
import java.util.List;

@Service
@Slf4j
public class BizScenicServiceImpl implements IBizScenicService {

    @Autowired
    BizScenicMapper bizScenicMapper;

    @Override
    public List<BizScenic> getList(BizScenic bizScenic) {
       return bizScenicMapper.selectList(bizScenic);
    }

    @Override
    public BizScenic getInfoByUserId(Integer userId) {
        try {
            BizScenic bizScenic = new BizScenic();
            bizScenic.setUserId(userId);
            BizScenic scenic = bizScenicMapper.selectList(bizScenic).get(0);
            if(scenic.getScenicImgs() == null){
                String[] arr = new String[0];
                scenic.setScenicImgs(arr);
            }
            return scenic;
        }catch (Exception e){
            return null;
        }
    }

    @Override
    public BizScenic getInfoById(Integer scenicId) {
        try {
            return bizScenicMapper.selectByPrimaryKey(scenicId);
        }catch (Exception e){
            return null;
        }
    }

    @Override
    public int add(BizScenic bizScenic) {
        return bizScenicMapper.insertSelective(bizScenic);
    }

    @Override
    public int edit(BizScenic bizScenic) {
        return bizScenicMapper.updateByPrimaryKeySelective(bizScenic);
    }

    @Override
    public int delete(BizScenic bizScenic) {
        return bizScenicMapper.updateByPrimaryKeySelective(bizScenic);
    }
}
